/*
 * 该js与table.css配合使用
 * basePath及modifyFlag在引用ext_jsp_templete.js需要先定义，否则部分功能可能无法正确执行
 * basePath指项目url地址 modifyFlag：标识可编辑区域是否修改 2010-9-9:fc
 * 2010-10-16：修订ie6底下jquery 选择器-属性选择器无法正常使用问题(可能是jsp页面问题,html测试可以使用)
 * 
 */
$(function() {
			/*try{
				if(loadType == "2"){
					//input
					//select
					lockInfoEditor();
				}
			}catch(e){
				
			}*/
			var documentHeight = 0;
			if($("body").innerHeight()>document.documentElement.clientHeight)
				documentHeight = $("body").innerHeight();
			else
				documentHeight = document.documentElement.clientHeight;
			var documentWidth = 0;
			if($("body").innerWidth()>document.documentElement.clientWidth)
				documentWidth = $("body").innerWidth();
			else
				documentWidth = document.documentElement.clientWidth;
			var zoneCode1,zoneCode2,zoneCode3,zoneCode4;
			var comboxWithTree;
			// 渲染页面表格中按钮
			$("input[type='button']").not($(".tb"))
					.css("background","url("+ basePath+ "ext/resources/images/default/toolbar/bg.gif) repeat-x").addClass("x-button-css")
			$("#dataload").css("top",(documentHeight - 50) / 2 + "px")
					.css("left",(documentWidth - 200) / 2+ "px")
			$("#uploadDiv").css("top",(documentHeight - 200) / 2 + "px")
					.css("left",(documentWidth - 450) / 2+ "px")
			var toolbarH = 0;
			var queryH = 0;
			try{
				if($("#toolbar").outerHeight(true)>0)
					toolbarH = 30;
			}catch(e){
				toolbarH = 0;
			}
			try{
				queryH = $("#query").outerHeight(true);
			}catch(e){
				queryH = 0;
			}
			var heg = documentHeight
					- toolbarH
					- queryH
			$("#tablePanel").css("height", heg + "px");
			//初始化元素分割线
			$("img[name='grid-split']").attr("src",basePath+ "ext/resources/images/default/grid/grid-blue-split.gif")

			try{
				afterLoad();
			}catch(e){
			
			}
			/*if(loadType == "2"){
				//input
				//select
				lockInfoEditor();
			}*/
			
			try{
				if(/^T000/.exec(tempUser)){
					$("input[type='button']").not($(".tb")).css("display","none");
				}
			}catch(e){}
			
			try{
				$("#idcard").change(function(){
					var value = $(this).val();
					$(this).val(value.toUpperCase());
				})
			}catch(e){}
		})
		
function lockInfoEditor(){
	try{
		var sel = $(".readOnly");
		for(var i = 0; i < sel.length; i++){
			var htmlObj = sel.get(i);			
			var obj = $(htmlObj);
			try{
			if(htmlObj.tagName.toLowerCase()=="input"){
				if(obj.val()!='')
				obj.attr("readOnly",true).css("cursor","not-allowed").css("border","0px");
			}else
			if(htmlObj.tagName.toLowerCase()=="select"){
				var length = htmlObj.options.length
				 	var text = htmlObj.options[htmlObj.options.selectedIndex].text;
					var value = obj.val();
					if(value.replace(/(\s*)/g, "")=="")
						continue;
					obj.empty();
					obj.append("<option value="+value+">"+text+"</option>").css("cursor","not-allowed");
			}
			if(htmlObj.tagName.toLowerCase()=="span"||htmlObj.tagName.toLowerCase()=="div"){
				obj.remove("input:not([checked])");
			}
			}catch(e){
				continue;
			}
		}
	}catch(e){
	}
	
}
		

/*function checkLock(){
	if(loadType == "3"){
		lockAll();
	}
}*/




/**
 * 初始化查询栏
 */
function initQuery(){
	$("#query").css("background-color","#ECECEC")
}

/**
 * 初始化工具栏
 * queryButton : 1 查询按钮  / saveButton：2 保存按钮 / delButton：3 删除按钮 / exportButton :4 导出按钮 / crossButton : 5 审核按钮 
 * backButton :6 退回按钮  / exportTempletButton 7 导入模板下载按钮 /  queryImportButton： 8 导入excel数据按钮 / excelButton:9 在线excel编辑按钮
 * 需初始化的按钮 按如下示例 展示 "1,2,3"
 * 
 */
function initToolBar(btnStr){
	
//	$("#toolbar").css("background","url("+ basePath+ "ext/resources/images/default/toolbar/bg.gif) repeat-x")
	$("#toolbar").css("background-color","#ECECEC");
	var strArray = btnStr.split(",");
	for(var i=0; i<strArray.length;i++){
		var temp = strArray[i];
		switch(temp){
			case "1": $("#queryButton").attr("src",
					basePath + "ext/examples/shared/icons/fam/cog_edit.png");break;
			case "2":$("#saveButton").attr("src",
					basePath + "ext/examples/shared/icons/fam/add.gif");break;
			case "3":$("#delButton").attr("src",
					basePath + "ext/examples/shared/icons/fam/delete.gif");break;
			case "4":$("#exportButton")
					.attr("src",basePath+ "ext/examples/shared/icons/fam/application_go.png");break;
			case "5":$("#crossButton").attr("src",basePath + "ext/examples/shared/icons/fam/user_gray.png");break;
			case "6":$("#backButton").attr("src",basePath + "ext/examples/shared/icons/fam/rss_go.png");break;
			case "7":$("#exportTempletButton").attr("src",basePath+ "ext/examples/shared/icons/fam/application_go.png");break;
			case "8":$("#queryImportButton").attr("src",basePath + "ext/examples/shared/icons/fam/add.gif");break;
			case "9":$("#excelButton").attr("src",basePath + "ext/examples/shared/icons/fam/add.gif");break;
		}
	}
	
	// 按钮鼠标经过样式
			$("#toolbar span[title!=''],#queryDiv").mouseover(function() {
						$(this).removeClass("outBorder");
						$(this).addClass("overBorder");
					}).mouseout(function() {
						$(this).removeClass("overBorder");
						$(this).addClass("outBorder")
					})
			$("#toolbar span").addClass("outBorder");
}
		

		
/**
 * 点击修改框,
 * css 引用inputCss的dom在调用此方法后即可双击修改
 */
function modifyTable() {
	// 处理用户修改数据td
	$(".inputCss").dblclick(function() {
		var obj = $(this);
		if (obj.children("input").length > 0) {
			return false;
		}
		var text = obj.html();
		obj.html("");
		txtObj = $("<input name='' onKeyPress='if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46)event.returnValue=false' type='text'>")
				.val(text).width(obj.width() / 2).height("20px").css("border",
						"0").css("text-align", "right").css("background-color",
						obj.css("background-color")).appendTo(obj);
		txtObj.trigger("focus").trigger("select");
		txtObj.click(function() {
					return false;
				});

		txtObj.keyup(function(event) {
					var keyCode = event.which;// 键码
					if (keyCode == 13) { // 回车键
						var editData = txtObj.val();
						if (editData == text) {
							obj.html(text);
						} else {
							obj.html(editData);
							modifyFlag = true;
						}
					} else if (keyCode == 27) { // ESC键
						obj.html(text);
					}
				});
		txtObj.blur(function() {
					var editData = txtObj.val();
					if (editData == text) {
						obj.html(text);
					} else {
						obj.html(editData);
						modifyFlag = true;
					}
				})
	}).css("cursor", "pointer")

}


/**
 * 地区初始化
 * @param {} loadId 加载span id
 * @param {} initLevel 地区加载级别
 * @param {} currentdistrictCode 当前用户地区编码
 * @param {} treeClickFunction 树点击事件方法
 */
function initDistrict(loadId, initLevel,currentdistrictCode,treeClickFunction,val) {
  var flag = false;
  var toobarObj = $("#toolbar");
  if(toobarObj.attr("id")!=undefined){
  	 flag = true;
  }
  try{
	  if(flag)
	  	$("#toolbar").attr("disabled",true);
  }catch(e){}
	Ext.useShims = true;
  zoneCode1 = new Ext.ux.StepTreeCombo({
	    width: 150,
	    tabIndex :-100,
	    lazyInit:false,
	    editable: false,
//	    dataUrl : basePath+'userInfo/buildTreeDistrictJSON4StepCombo.action?dlevel='+initLevel+'&gbcode='+ currentdistrictCode,
	     dataUrl: getUUMSTreeUrl(initLevel,currentdistrictCode),
	    treeConfig: {
	        rootVisible:false,
	        height: 210,
	        autoScroll:true,
	        root: new Ext.tree.TreeNode({expanded : true,text: '根目录',id:'0'})
	    }
	    ,listeners:{
	        select:function() {
	            if (zoneCode1.getValue() != '') {
					treeClickFunction();
	            }
	        }
	    }
	});
	zoneCode1.treePanel.on('load', function() {
		if(val!=undefined&&val!=''){
			try{
				var node = zoneCode1.treePanel.getNodeById(val.substring(0,10));
				if(node!=undefined){
					val = val.substring(0,10)+node.text;
				}
			}catch(e){}
			zoneCode1.setRawValue(val);
		}
		else
	   		zoneCode1.setValue(currentdistrictCode);
	    Ext.MessageBox.hide();
	    try{
	     if(flag)
  			$("#toolbar").attr("disabled",false);
  		}catch(e){}
	});
	
	zoneCode1.render(Ext.get(loadId));
}

function initDistrictDyn(loadId, initLevel,currentdistrictCode,val,zoneObj,treeClickFunction) {
	Ext.useShims = true;
  var zoneCode1 = new Ext.ux.StepTreeCombo({
	    width: 150,
	    lazyInit:false,
	    editable: false,
//	    dataUrl : basePath+'userInfo/buildTreeDistrictJSON4StepCombo.action?dlevel='+initLevel+'&gbcode='+ currentdistrictCode,
	     dataUrl: getUUMSTreeUrl(initLevel,currentdistrictCode),
	    treeConfig: {
	        rootVisible:false,
	        height: 210,
	        autoScroll:true,
	        root: new Ext.tree.TreeNode({expanded : true,text: '根目录',id:'0'})
	    }
	    ,listeners:{
	        select:function() {
	            if (zoneCode1.getValue() != '') {
					treeClickFunction();
	            }
	        }
	    }
	});
	zoneCode1.treePanel.on('load', function() {
		if(val!=undefined&&val!=''){
			try{
				var node = zoneCode1.treePanel.getNodeById(val.substring(0,10));
				if(node!=undefined){
					val = val.substring(0,10)+node.text;
				}
			}catch(e){}
			zoneCode1.setRawValue(val);
		}
		else
	   		zoneCode1.setValue("");
	    Ext.MessageBox.hide();
	});
	switch(zoneObj){
		case "2":zoneCode2 = zoneCode1;zoneCode2.render(Ext.get(loadId));break;
		case "3":zoneCode3 = zoneCode1;zoneCode3.render(Ext.get(loadId));break;
		case "4":zoneCode4 = zoneCode1;zoneCode4.render(Ext.get(loadId));break;
	}
	
}



/**
 * 初始化下拉框
 * @param {} selectId select元素Id
 * @param {} json     json 格式填充数据 string
 * @param {} selectValue 选中值
 * @param {} extraFun    初始化时额外处理方法
 */
function initSelect(selectId,jsondata,selectValue,extraFun){

	var selectDom = $("#"+selectId);
	selectDom.empty();
	var json;
	try{
		json = eval('('+jsondata+')');
	}catch(e){
		json = jsondata;
	}
	selectDom.append("<option value=''>--请选择--</option>");
	for (var i = 0; i < json.length; i++) {
		var val = json[i]['code'] + "";
		var text = json[i]['name'] + "";
		if(val==selectValue)
		selectDom.append("<option value=" + val + " selected='selected''>" + text
				+ "</option>");
		else
				selectDom.append("<option value=" + val + ">" + text
				+ "</option>");
	}
	 extraFun();
}

/**
 * 提交表单
 * @param {} saveBtnId 多个id之间用“，”隔开
 * @param {} subUrl       提交路径,参数可以由Params提供
 * @param {} formName  表单Id
 * @param {} params	可选  json格式参数数据格式的字符串,如果没有用""代替
 * @param {} extraFun  表单验证方法
 */
function formSub(saveBtnId,subUrl,formName,params,extraFun){

	var subBtn = $("#"+saveBtnId);
	subBtn.click(function(){
		
		var flag = extraFun();
		if(!flag){
			return;
		}
		if($("#communityNum").val()=='${userInfo.districtCode}'){
			alert("请选择所在地区");
			return;
		}
		url = subUrl;
		var flag = true;
		   	if(null!=params && ""!=params){
			   	if(url.indexOf("?")!=-1){
			   		flag = false;
			   	}
			   	var json ;
			   	try{
					json = eval('('+params+')');
				}catch(e){
					json = params;
				}
				
	      	 	for(var i = 0; i < json.length; i++){
	      	 		for(var key in json[i]){
		      	 		var value = json[i][key];
			      	 		if(i==0&&flag==true)
		      	 			url = url + "?"+key+"="+value;
		      	 		else
		      	 			url = url + "&"+key+"="+value;
	      	 		}
	      	 	}
      	 }
      	 var formArray = document.forms;
      	 for (var i=0;i<formArray.length;i++){
      	 	if(document.forms[i].id==formName){
      	 		$("#"+formName).attr("action",url)
      	 		document.forms[i].submit();
      	 	}
      	 }
	})
}

/**
 * 设置td高度
 * @param {} heightValue
 */
function setTdHeight(heightValue){
	$("#tablePanel table td").css("height",heightValue+"px");
}

/**
 * 动态给span加载元素
 * @param {} panelId 目标id
 * @param {} json	  json数据格式数据 string
 * @param {} count	  每行显示数 int
 * @param {} type 1:checkbox 2:radio 
 * @param {} elementName 元素名
 * @param {} align 显示位置
 */
function fillPanel(panelId,jsondata,count,type,elementName,defaultValue,align){
	var json ;
   	try{
		json = eval('('+jsondata+')');
	}catch(e){
		json = jsondata;
	}
	var index=1;
	var str = "<table width='100%' ><tr>";
	$("#"+panelId).empty();
	for (var i = 0; i < json.length; i++) {
		var code = json[i]['code'] + "";
		var name = json[i]['name'] + "";
		
		if(type == "1"){
			str += "<td style='border:0px;text-align:"+align+"'><label><input type='checkbox' name='"+elementName+"' value='"+code+"'";
			if((","+defaultValue.replace(/(\s*)/g, "")+",").indexOf(","+code.replace(/(\s*)/g, "")+",")!=-1)
				str += "checked='checked'";
			str += "/> "+name+"<label></td>";
		}else {
			str += "<td style='text-align:"+align+"'><label><input type='radio' name='"+elementName+"' value='"+code+"'";
			if(defaultValue==code)
				str += "checked='checked'";
			str += "/> "+name+"</label></td>";
		}
		if(index == count){
			str += "</tr><tr>";
			index = 0;
		}
		index++;
	}
	str +="</table>";
	$("#"+panelId).html(str);
}



function initData2Field(jsonStr){
	var code = '';
	var name = '';
 	if(null!=jsonStr && ""!=jsonStr){
 			var json;
 			try{
      	 		json = eval('('+jsonStr+')');
 			}catch(e){
 				json = jsonStr;
 			}
      	 	for(var i = 0; i < json.length; i++){
  	 			for(var key in json[i]){
  	 				var value = json[i][key];
	      	 		if(key=='communityNum'){
      	 			if(code == "")
      	 				code = value;
	      	 		}
	      	 		if(key=='communityName'){
	      	 			if(name == "")
	      	 				name = value;
	      	 		}
	      	 		if(value == 'null'||value == 'null')
	      	 			continue;
	      	 		if($("#"+key).length==0){
	      	 			value = value.replace(/(\s*)/g, "");
	      	 			buildRadioList(key,value);
	      	 			buildCheckboxList(key,value);
	      	 		}else
	      	 			$("#"+key).val(value);
      	 		}
      	 	}
  	 }
  	 zoneCode1.setRawValue(code+name);
  	 lockInfoEditor();
}


function lockAll(hideIdArray){
	$("input,select").attr("disabled",true)
	try{
		if(hideIdArray!=undefined&&hideIdArray!=''){
			hideIdArray = hideIdArray.replace(/(\s*)/g, "").replace(',', ", #");
			$("#"+hideIdArray).css("display","none");
		}
	}catch(e){
		
	}
//	zoneCode1.disable()
	$("#query").css("display","none");
}


function buildCheckboxList(name,value){
	var chkother= document.getElementsByTagName("input");
	for (var i=0;i<chkother.length;i++)
	{
	   if( chkother[i].type=='checkbox')
	   {
	    if(chkother[i].name.indexOf("."+name)>-1)
	    {
	    	if((","+value+",").indexOf(","+chkother[i].value.replace(/(\s*)/g, "")+",")!=-1){
	      	 		chkother[i].checked=true;
	      	 }
	    }
	   }
	}
}

function buildRadioList(name,value){
	var chkother= document.getElementsByTagName("input");
	for (var i=0;i<chkother.length;i++)
	{
	   if( chkother[i].type=='radio')
	   {
	    if(chkother[i].name.indexOf("."+name)>-1)
	    {
	    	if(chkother[i].value==value){
	      	 		chkother[i].checked=true;
	      	 }
	    }
	   }
	}
}


// 身份证验证 hezn
function checkIdcard(idcard) {
	var Errors = new Array("", "身份证号码位数不对!", "身份证号码出生日期超出范围或含有非法字符!",
			"身份证号码校验错误!", "身份证地区非法!");
	var area = {
		11 : "北京",
		12 : "天津",
		13 : "河北",
		14 : "山西",
		15 : "内蒙古",
		21 : "辽宁",
		22 : "吉林",
		23 : "黑龙江",
		31 : "上海",
		32 : "江苏",
		33 : "浙江",
		34 : "安徽",
		35 : "福建",
		36 : "江西",
		37 : "山东",
		41 : "河南",
		42 : "湖北",
		43 : "湖南",
		44 : "广东",
		45 : "广西",
		46 : "海南",
		50 : "重庆",
		51 : "四川",
		52 : "贵州",
		53 : "云南",
		54 : "西藏",
		61 : "陕西",
		62 : "甘肃",
		63 : "青海",
		64 : "宁夏",
		65 : "新疆",
		71 : "台湾",
		81 : "香港",
		82 : "澳门",
		91 : "国外"
	}
	var idcard, Y, JYM;
	var S, M;
	var idcard_array = new Array();
	idcard_array = idcard.split("");
	// 地区检验
	if (area[parseInt(idcard.substr(0, 2))] == null)
		return Errors[4];
	// 身份号码位数及格式检验
	switch (idcard.length) {
		case 15 :
			if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0
					|| ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard
							.substr(6, 2)) + 1900)
							% 4 == 0)) {
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;// 测试出生日期的合法性
			} else {
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;// 测试出生日期的合法性
			}
			if (ereg.test(idcard))
				return Errors[0];
			else {

				return Errors[2];
			}
			break;
		case 18 :
			// 18位身份号码检测
			// 出生日期的合法性检查
			// 闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
			// 平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
			if (parseInt(idcard.substr(6, 4)) % 4 == 0
					|| (parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard
							.substr(6, 4))
							% 4 == 0)) {
				ereg = /^[1-9][0-9]{5}[1-2][0-9][0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9XxTP]$/;// 闰年出生日期的合法性正则表达式
			} else {
				ereg = /^[1-9][0-9]{5}[1-2][0-9][0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9XxTP]$/;// 平年出生日期的合法性正则表达式
			}

			if (ereg.test(idcard)) {// 测试出生日期的合法性
				/* 计算校验位
				S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10]))
						* 7
						+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11]))
						* 9
						+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12]))
						* 10
						+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13]))
						* 5
						+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14]))
						* 8
						+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15]))
						* 4
						+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16]))
						* 2 + parseInt(idcard_array[7]) * 1
						+ parseInt(idcard_array[8]) * 6
						+ parseInt(idcard_array[9]) * 3;
				Y = S % 11;
				M = "F";
				JYM = "10X98765432";
				M = JYM.substr(Y, 1);// 判断校验位
				if (M == idcard_array[17] || 'P' == idcard_array[17]
						|| 'T' == idcard_array[17])*/
				if(/^[0-9XxTP]{1}$/.test(idcard_array[17]))
					return Errors[0]; // 检测ID的校验位
				else
					return Errors[3];
			} else {
				return Errors[2];
			}
			break;
		default :
			return Errors[1];
			break;
	}
}

// 15位身份证转18位 start
function cardID15to18(cardID) {
	var v = new Array();
	var vs = "10X98765432";
	v.push(2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7);
	var month = cardID.substring(8, 10);// 获得15位号码中的月份
	var year = "19" + cardID.substring(6, 8);
	var day = cardID.substring(10, 12);
	// 将15位的号码转换位17位
	var cardID17 = cardID.substring(0, 6) + "19" + cardID.substring(6);
	var N = 0;
	var R = -1;
	var T = '0';// 储存最后一个数字
	var j = 0;
	var cardID18 = "";
	for (var i = 16; i >= 0; i--) {
		N += parseInt(cardID17.substring(i, i + 1)) * v[j];
		j++;
	}
	R = N % 11;
	T = vs.charAt(R);
	cardID18 = cardID17 + T;
	return cardID18;
}

// 15位身份证转18位 end



function abc(selectId,effectId){
	  		var sel = $("#"+selectId);
	  		var effect = $("#"+effectId);
	  		var value = sel.val();
	  		if(value == "1" || value == ""){
	  			effect.val("");
	  			effect.attr("disabled",true);
	  		}else{
	  			effect.attr("disabled",false);
	  		}
	}
	
/**
 * 
 * @param {} string id@length@fieldName@type 
 * id 组件id
 * length 输入最大长度
 *  fieldName 对应字段名
 *  type 1:表示允许为空
 *  	2：表示不允许为空
 * @return {Boolean}
 */
function checkBlank(string){
	try{
		var strArray = string.split(",");
		for(var i=0; i < strArray.length; i++){
			var tempArray = strArray[i].split("@");
			var obj = $("#"+tempArray[0]);
			if(obj.val()==""){
			if(tempArray[3]!=undefined&&tempArray[3]=="1")
					continue;
				alert(tempArray[2]+"不能为空");
				obj.focus();
				obj.css("border-bottom","1px solid red");
				return false;
			}
			else if(obj.val().length>parseInt(tempArray[1])){
				obj.focus();
				alert(tempArray[2]+"的最大长度为"+tempArray[1]);
				obj.css("border-bottom","1px solid red");
				return false;
			}
			obj.css("border-bottom","1px solid black");
			
		}
		return true;
	}catch(e) {
	}
	
}

jQuery.fn.clearCheckBox=function clearCheckBox(value){
$(this).click(function(){
	var recentValue = $(this).val().replace(/(\s*)/g, "");
	var name = $(this).attr("name");
	if(!$(this).attr("checked"))
		return;
	var checkboxElements = document.getElementsByName(name);
	for(var i = 0;i < checkboxElements.length; i++){
		var element = checkboxElements[i];
		if(recentValue == element.value.replace(/(\s*)/g, ""))
			continue;
		if(element.value.replace(/(\s*)/g, "") == value.replace(/(\s*)/g, "")){
			if(recentValue!=value.replace(/(\s*)/g, ""))
			element.checked = false;
			return;
		}
		if(recentValue == value.replace(/(\s*)/g, ""))
			if(element.checked){
				element.checked = false;
			}
	}
})
}

function checkBoxSelect(name){
	var checkboxElements = document.getElementsByName(name);
	for(var i = 0;i < checkboxElements.length; i++){
		var element = checkboxElements[i];
		if(element.checked){
			return true;
		}
	}
	return false;
}


var formEditFlag = false;
function checkFormUpdate(formId) {
	$("#"+formId+" select,#"+formId+" input").change(function(){
		formEditFlag = true;
	})
}



var submitPageFlag = true;
function checkLeave(){
	if(formEditFlag&&submitPageFlag){
		event.returnValue="您的数据尚未保存?";
	}
}

function onlyNum()
{
    if (!((event.keyCode >= 48 && event.keyCode <= 57 )
		|| (event.keyCode >= 96 && event.keyCode <= 105)
		|| (event.keyCode >= 37 && event.keyCode <= 40)||event.keyCode==110||event.keyCode==190))
    //考虑小键盘上的数字键
        if (event.keyCode != 8&&event.keyCode != 13)event.returnValue = false;
    //  return false;
}
